﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="~/script/jquery.js"></script>
    <style>
        .hidden{
            display:none;
        }
        .red{
            color:red;
        }
    </style>
</head>
<body>
    <div>
        @using (Html.BeginForm())
        {
            <p>
                用户名：<input id="username" type="text" name="username" onblur="checkUsername" />
                <span class="hidden red" id="userNameTips">请输入用户名</span>
            </p>
            <p>
                密码：<input id="password" type="text" name="password" onblur="checkpwd" />
            </p>
            <p>
                确认密码：<input id="password2" type="text"  onblur="checkpwd" />
            </p>
            <p><span class="hidden red" id="pwdTips">请输入密码</span></p>
            <p><span class="hidden red" id="pwdTips2">两次密码输入不一致，请重新输入密码</span></p>
            <input id="Button1" type="submit" value="提交" />
        }
    </div>
    <script>
        
        function checkUsername() {
            if ($("#username").val() == "" ) {
                $("#userNameTips").removeClass("hidden");
                return false;
            } else {
                $("#userNameTips").addClass("hidden");
                return true;
            }
        }
        //密码非空判断
        function checkpwd() {
            if ($("#password").val() == "" || $("#password2").val() == "") {
                $("#pwdTips").removeClass("hidden");
                return false;
            } else {
                $("#pwdTips").addClass("hidden");

                if ($("#password").val() != $("#password2").val()) {
                    $("#pwdTips2").removeClass("hidden");
                    return false;
                } else {
                    $("#pwdTips2").addClass("hidden");
                    return true;
                }
                return true;
            }
        }
       
        function checkForm() {
            return checkUsername() && checkpwd();
        }
        $(document).ready(function () {
            $("form").bind("submit",checkForm)
        })
    </script>
</body>
</html>
